﻿<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Cars"
             xmlns:vm="clr-namespace:Cars.ViewModels"
             x:Class="Cars.MainPage"
             BindingContext="{DynamicResource VM}"
             Background="#222831">
    <ContentPage.Resources>
        <vm:MainViewModel x:Key="VM"/>
    </ContentPage.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="5"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="7*"/>
        </Grid.RowDefinitions>
        <Label HorizontalOptions="Center" VerticalOptions="Center" FontAttributes="Italic"  Text="CarList" FontSize="48" TextColor="#FF5722"/>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Button x:Name="CarsButton" Grid.Column="0" Text="Автомобили" FontAttributes="Bold" Background="#2D4059" TextColor="#FF5722" Clicked="CarsVisible"/>
            <Button x:Name="EnginesButton" Grid.Column="1" Text="Двигатели" FontAttributes="Bold" Background="#2D4059" TextColor="#EEEEEE" Clicked="EnginesVisible"/>
            <Button x:Name="BodyTypesButton" Grid.Column="2" Text="Кузова" FontAttributes="Bold" Background="#2D4059" TextColor="#EEEEEE" Clicked="BodyTypesVisible"/>
        </Grid>
        <Rectangle Grid.Row="2" HeightRequest="5" Fill="#2D4059"/>
        
        <!--Cars-->
        <Button x:Name="AddCar" Grid.Row="3" Text="Добавить" FontSize="30" FontAttributes="Bold" Background="#2D4059" TextColor="#EEEEEE" Command="{Binding AddCar}"/>
        <CollectionView x:Name="CollectionCars" IsVisible="true" Margin="10" Grid.Row="4" ItemsSource="{Binding Cars}" SelectedItem="{Binding SelectedCar}" SelectionMode="Single" >
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame BackgroundColor="Transparent" Margin="10" CornerRadius="10" BorderColor="#2D4059" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="3*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Label Text="{Binding Model}" FontAttributes="Bold" FontSize="20" TextColor="#EEEEEE"/>
                            <Label Grid.Row="1" Text="{Binding Description}" TextColor="#EEEEEE"/>
                            <Label Grid.Row="2" Text="{Binding EngineView}" TextColor="#EEEEEE"/>
                            <Label Grid.Row="3" Text="{Binding BodyTypeView}" TextColor="#EEEEEE"/>
                            <Button Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="✎" Command="{Binding Source={StaticResource VM}, Path=EditCar}" CommandParameter="{Binding Id}" FontSize="34" Background="#2D4059" TextColor="#FF5722"/>
                            <Button Grid.Row="2" Grid.RowSpan="2" Grid.Column="1" Text="🗑" Command="{Binding Source={StaticResource VM}, Path=DeleteCar}" CommandParameter="{Binding}" FontSize="30" Background="#2D4059" TextColor="#FF5722"/>
                        </Grid>
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <!--Engines-->
        <Button x:Name="AddEngine" IsVisible="false" Grid.Row="3" Text="Добавить" FontSize="30" FontAttributes="Bold" Background="#2D4059" TextColor="#EEEEEE" Command="{Binding AddEngine}"/>
        <CollectionView x:Name="CollectionEngines" IsVisible="false" Margin="10" Grid.Row="4" ItemsSource="{Binding Engines}" SelectedItem="{Binding SelectedEngine}" SelectionMode="Single" >
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame BackgroundColor="Transparent" Margin="10" CornerRadius="10" BorderColor="#2D4059" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="3*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Row="0" Text="{Binding Model}" FontAttributes="Bold" FontSize="20" TextColor="#EEEEEE"/>
                            <Label Grid.Row="1" Text="{Binding Path=CylinderArrangement, StringFormat='Расположение цилиндров: {0:F1}'}" TextColor="#EEEEEE" />
                            <Label Grid.Row="2" Text="{Binding Path=CylinderCapacity, StringFormat='Объём: {0:F1} л.'}" TextColor="#EEEEEE" />
                            <Label Grid.Row="3" Text="{Binding Path=HorsePower, StringFormat='Мощность: {0} л.с.'}" TextColor="#EEEEEE" />
                            <Button Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="✎" Command="{Binding Source={StaticResource VM}, Path=EditEngine}" CommandParameter="{Binding Id}" FontSize="34" Background="#2D4059"  TextColor="#FF5722"/>
                            <Button Grid.Row="2" Grid.RowSpan="2" Grid.Column="1" Text="🗑" Command="{Binding Source={StaticResource VM}, Path=DeleteEngine}" CommandParameter="{Binding}" FontSize="30" Background="#2D4059" TextColor="#FF5722"/>
                        </Grid>
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <!--BodyTypes-->
        <Button x:Name="AddBodyType" IsVisible="false" Grid.Row="3" Text="Добавить" FontSize="30" FontAttributes="Bold" Background="#2D4059" TextColor="#EEEEEE" Command="{Binding AddBodyType}"/>
        <CollectionView IsVisible="false" x:Name="CollectionBodyTypes" Margin="10" Grid.Row="4" ItemsSource="{Binding BodyTypes}" SelectedItem="{Binding SelectedBodyType}" SelectionMode="Single" >
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame BackgroundColor="Transparent" Margin="10" CornerRadius="10" BorderColor="#2D4059" >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="2*"/>
                            </Grid.ColumnDefinitions>
                            <Label Text="{Binding Title}" Grid.RowSpan="2" FontAttributes="Bold" FontSize="20" TextColor="#EEEEEE"/>
                            <Button  Grid.Column="1"  HorizontalOptions="EndAndExpand" Text="✎" Command="{Binding Source={StaticResource VM}, Path=EditBodyType}" CommandParameter="{Binding Id}" FontSize="34" Background="#2D4059" TextColor="#FF5722"/>
                            <Button  Grid.Column="1"  HorizontalOptions="StartAndExpand"  Text="🗑" Command="{Binding Source={StaticResource VM}, Path=DeleteBodyType}" CommandParameter="{Binding}" FontSize="30" Background="#2D4059" TextColor="#FF5722"/>
                        </Grid>
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

    </Grid>
</ContentPage>
